package CSR_V3;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

class Simulateur {

	static final int NB_CLIENTS = 20;

	public void work() {
		try {
			Billeterie b = null;

			System.out.print("Installing security manager...");
			if (System.getSecurityManager() == null) {
				System.setSecurityManager(new SecurityManager());
			}
			System.out.println("done.");

			System.out.print("Getting the registry...");
			Registry registry = LocateRegistry.getRegistry();
			System.out.println("done.");

			System.out.print("Getting the stub...");
			b = (Billeterie) registry.lookup("sncf");
			System.out.println("done.");

			for (int i = 0; i < NB_CLIENTS; i++) {
				(new Client(b, 2)).start();
			}

			while (true) {
				Thread.sleep(1000);
				b.ajouterTickets(3);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	} // work

	public static void main(String args[]) {
		Simulateur s = new Simulateur();
		s.work();
	}

}
